import FeatureLayer from "@geoscene/core/layers/FeatureLayer";
import PictureMarkerSymbol from "@geoscene/core/symbols/PictureMarkerSymbol";
import SimpleRenderer from "@geoscene/core/renderers/SimpleRenderer";
import { cluster } from "@/utils/gis/Cluster";



export function createLayer( options: any ) {

    const type:string = options.type;
    switch (type) {
        case "feature-point":
            let config = {
                id: options.id || undefined,
                url: options.url,
                title: options.title || "Feature Layer",
                opacity: options.opacity || 1,
                visible: options.visible || true,
                popupTemplate: options.popupTemplate || null,
                featureReduction: options.featureReduction || cluster(),
                outFields: options.outFields || ["*"],
                definitionExpression: options.definitionExpression || '1=1',
                minScale: options.minScale || 0,
                maxScale: options.maxScale || 0,
                elevationInfo: options.elevationInfo || null,
                labelingInfo: options.labelingInfo || [],
                renderer: createRenderer(options.renderer),
            }
            const layer = new FeatureLayer(config);
            return layer;
            break;
        default:
            return undefined;
        }

}


export function createRenderer( options: any ) {
    const type:string = options.type;
    switch (type) {
        case "simple":
            const symbol = options.symbol;
            const renderer = new SimpleRenderer({
                symbol: createSymbol(symbol),
            });
            return renderer;
            break;
        default:
            return undefined;
        }
}

export function createSymbol( options: any ) {
    const type:string = options.type;
    switch (type) {
        case "picture-marker":
            const symbol = new PictureMarkerSymbol({
                url: options.url,
                width: options.width || 24,
                height: options.height || 24,
            });
            return symbol;
            break;
        default:
            return undefined;
        }
}